<!DOCTYPE html>
<html class="x-admin-sm">
    {include file="Admin/Public/head" title="文章分类" /}

    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                    <input type="hidden" name="id"value="{$data['id']}">
                  <div class="layui-form-item">
                      <label for="username" class="layui-form-label">
                          <span class="x-red">*</span>分类标题
                      </label>
                      <div class="layui-input-inline">
                          <input type="text" id="name" name="name" value="{$data['name']}" autocomplete="off" class="layui-input">
                      </div>
                  </div>
                  <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>父级分类</label>
                        <div class="layui-input-inline">
                            <select name="parent_id" lay-filter="parent_id">
                                <option value="0">------</option>
                                {volist name="navs" id="val"}
                                <option value="{$val['id']}" data-path="{$val['path']}" {if $data['parent_id'] == $val['id']}selected{/if}>{$val['name']}</option>
                                {/volist}
                            </select>
                            <input type="hidden" id="path" name="path" value="{$data['path']}" />
                        </div>
                    </div>
                  <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>是否显示</label>
                        <div class="layui-input-inline">
                            <select name="display">
                                <option value="0" {if $data['display'] == 0}selected{/if}>显示</option>
                                <option value="1" {if $data['display'] == 1}selected{/if}>隐藏</option>
                            </select>
                        </div>
                    </div>
                  <div class="layui-form-item" id="is_show1">
                        <label for="username" class="layui-form-label" class="is_show1">
                            <span class="x-red">*</span>是否展示在首页</label>
                        <div class="layui-input-inline" class="is_show1">
                            <select name="is_show" id="is_show" layer-filter="is_show">
                                <option value="1" {if $data['is_show'] == 1}selected{/if}>是</option>
                                <option value="0" {if $data['is_show'] == 0}selected{/if}>否</option>
                            </select>
                        </div>
                    </div>
                  <div class="layui-form-item">
                      <label for="L_repass" class="layui-form-label">
                      </label>
                      <button  class="layui-btn" lay-filter="add" lay-submit="">
                          增加
                      </button>
                  </div>
              </form>
            </div>
        </div>
        <script>layui.use(['form', 'layer'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;

                form.on('select(parent_id)', function(data){
                    let option = $(data.elem).find("option:selected");
                    $("#path").val(option.attr("data-path"))
                    $("#is_show").val(0);
                    if (data.value == 0) {
                        $("#is_show1").show();
                    } else {
                        $("#is_show1").hide();
                    }
                    form.render("select");
                });

                //监听提交
                form.on('submit(add)', function(data) {
                    layer.load(2);
                    $.post("/admin/category/create", data.field, function(data){
                        layer.closeAll();
                        if (data.code == 200) {
                            layer.msg(data.msg, {time: 1500}, function(){
                                xadmin.close();
                                xadmin.father_reload();
                            })
                        } else if (data.code) {
                            layer.msg(data.msg)
                        }
                    })
                    return false;
                });

            });</script>
        <script>var _hmt = _hmt || []; (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();</script>
    </body>

</html>
